<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of IsChildEventAcceptable
 *
 * @author Schorr
 */
class Fkb_Validate_IsChildEventAcceptable extends Zend_Validate_Identical{
        
    const CHILD_EVENT_INVALID = 'dateInvalid';
    
    protected $_messageTemplates = array(
	self::CHILD_EVENT_INVALID => "Es ist kein Betreuungsplatz im Zeitraum verfügbar!");
    
     public function isValid($value, $context = null){
	
	$this->_setValue((string) $value);
        if (($context !== null) && isset($context) && array_key_exists($this->getToken(), $context)) {
            $token = $context[$this->getToken()];
        } else {
            $token = $this->getToken();
        }

	$me = new Model_Event();
	$mc = new Model_Child();
	$child = $mc->find($context['child_id']);
	if(!isset($context['event_id']))
	    $context['event_id']=$context['id'];
	$event = $me->find($context['event_id']);
	$event['date_from']=$context['date_from'];
	$event['date_to']=$context['date_to'];
	if(isset($context['event_status']))
	    $event['event_status']=$context['event_status'];
	if($me->getAcceptedStatus($child, $event) == 'Angenommen'){
	    return true;
	}
	else {
	    $this->_error(self::CHILD_EVENT_INVALID);
	    return false;
     }
     }
}

?>
